class Solution {
public:
    int lengthOfLongestSubstring(string s) 
    {
        //利用数组模拟哈希表
        int hash[128] = {0};
    
        int left = 0, right = 0, n = s.size(), ret = 0;

        while(right < n)
        {
            //进入窗口
            hash[s[right]]++;
            //判断
            while(hash[s[right]] > 1)
                hash[s[left++]]--;
            //更新结果
            ret = max(ret, right-left+1);

            right++;
        }
        return ret;
    }
};

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) 
    {
        int left = 0, right = 0, n = nums.size(),count = 0,ret = 0;

        while(right < n)
        {
            //判断
            if(nums[right] == 0)
                count++;

            //进窗口
            right++;
            

            //出窗口
            while(count > k)
            {
                if(nums[left++] == 0)
                    count--;
            }
            
            //更新结果
            ret = max(ret,right-left);

        }
        return ret;
    }
};
